//
//  SmallCell.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/15.
//

#import "SmallCell.h"
#import <SDWebImage/SDWebImage.h>
@interface SmallCell()
@property (nonatomic,strong)UIImageView *bg;
@property (nonatomic,strong)UIView *btn;
@property (nonatomic,strong)UIImageView *logo;
@property(nonatomic,strong)UILabel *mLabel;
@property(nonatomic,strong)UILabel *bname;
@property(nonatomic,strong)UILabel *rateLabel;
@property(nonatomic,strong)UILabel *termLabel;
@property(nonatomic,strong)UILabel *rateLabelt;
@property(nonatomic,strong)UILabel *termLabelt;

@end
@implementation SmallCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor =UIColor.clearColor;
        [self setUpUI];
    }
    return self;
}

-(void)setUpUI{
    UIView *view  = [UIView new];
    view.backgroundColor = UIColor.clearColor;
    [self.contentView addSubview:view];
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(13);
        make.top.mas_offset(0);
        make.right.mas_offset(-13);
        make.height.mas_equalTo(120);
        make.bottom.mas_offset(-20);
    }];
    [view addSubview:self.bg];
    [_bg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.mas_offset(0);
    }];
    [view addSubview:self.logo];
    [_logo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(8);
        make.left.mas_offset(12);
        make.size.mas_equalTo(CGSizeMake(24, 24));
    }];
    [view addSubview:self.name];
    [_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(_logo);
        make.left.equalTo(_logo.mas_right).offset(5);
    }];
    [view addSubview:self.btn];
    [_btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(view);
        make.right.mas_offset(-15);
        make.size.mas_equalTo(CGSizeMake(102, 38));
    }];
    UILabel *plab = [UILabel new];
    plab.font = [UIFont systemFontOfSize:20 weight:UIFontWeightMedium];
    plab.textColor = HexColor(@"#000000");
    plab.text = @"";
    [view addSubview:plab];
    [plab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(12);
        make.centerY.mas_equalTo(view);
    }];
    [view addSubview:self.mLabel];
    [_mLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(plab.mas_right).offset(2);
        make.centerY.mas_equalTo(view);
    }];
    UILabel *rate = [UILabel new];
    rate.font = [UIFont systemFontOfSize:12 ];
    rate.textColor = DetailColor;
    rate.text = @"Interest rate";
    [view addSubview:rate];
    _rateLabelt = rate;
    [rate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(12);
        make.bottom.mas_offset(-11);
    }];
    
    [view addSubview:self.rateLabel];
    [_rateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(rate.mas_right).offset(6);
        make.centerY.mas_equalTo(rate);
    }];
    
    UILabel *term = [UILabel new];
    term.font = [UIFont systemFontOfSize:12 ];
    term.textColor = DetailColor;
    term.text = @"Interest rate";
    _termLabelt = term;
    [view addSubview:term];
    [term mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_offset(12);
        make.bottom.mas_offset(-11);
    }];
    
    [view addSubview:self.termLabel];
    [_termLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(term.mas_right).offset(12);
        make.centerY.mas_equalTo(term);
    }];
    
}
-(UILabel *)name
{
    if (!_name) {
        _name = [UILabel new];
        _name.font = [UIFont systemFontOfSize:14 weight:UIFontWeightBold];
        _name.textColor = HexColor(@"#0B9700");
    }
    return _name;
}
-(UILabel *)bname
{
    if (!_bname) {
        _bname = [UILabel new];
        _bname.font = [UIFont systemFontOfSize:16 weight:UIFontWeightBold];
        _bname.textColor = HexColor(@"#ffffff");
    }
    return _bname;
}

-(UIImageView *)bg
{
    if (!_bg) {
        _bg = [UIImageView new];
        _bg.image = [UIImage imageNamed:@"home_small_cellbg"];
        _bg.contentMode = UIViewContentModeScaleToFill;
        
    }
    return _bg;
}
-(UIImageView *)logo
{
    if(!_logo){
        _logo = [UIImageView new];
        _logo.image = [UIImage imageNamed:@"Clogo"];
        _logo.contentMode = UIViewContentModeScaleAspectFit;
        _logo.layer.cornerRadius = 4;
        _logo.layer.masksToBounds = YES;
    }
    return _logo;
}
-(UIView *)btn
{
    if (!_btn) {
        _btn = [UIView new];
        _btn.backgroundColor = HexColor(@"#90DA01");
        _btn.layer.cornerRadius = 19;
        [_btn addSubview:self.bname];
        [_bname mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(_btn);
        }];

    }
    return _btn;
}
-(UILabel *)mLabel
{
    if (!_mLabel) {
        _mLabel = [UILabel new];
//        _mLabel.text = @"80,000";
        _mLabel.textColor = HexColor(@"#000000");;
        _mLabel.font = [UIFont systemFontOfSize:44 weight:UIFontWeightBold];
    }
    return _mLabel;
}
-(UILabel *)rateLabel
{
    if (!_rateLabel) {
        _rateLabel = [UILabel new];
//        _rateLabel.text = @"0.03%/day";
        _rateLabel.textColor = HexColor(@"#000000");
        _rateLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    }
    return _rateLabel;
}
-(UILabel *)termLabel
{
    if (!_termLabel) {
        _termLabel = [UILabel new];
//        _termLabel.text = @"300days";
        _termLabel.textColor = HexColor(@"#000000");
        _termLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
    }
    return _termLabel;
}

-(void)setSource:(NSDictionary *)source
{
    _mLabel.text = CPS(source[@"voicethe"]);
    _rateLabelt.text = CPS(source[@"remarkedive"]);
    _rateLabel.text = CPS(source[@"worried"]);
    _termLabelt.text = CPS(source[@"trouble"]);
    _termLabel.text = CPS(source[@"earthquake"]);
    [_logo sd_setImageWithURL:[NSURL URLWithString:CPS(source[@"sorrow"])] placeholderImage:[UIImage imageNamed:@"Clogo"]];
    _bname.text =  CPS(source[@"deckwhat"]);
    _name.text = CPS(source[@"continued"]);
}
@end
